package main

import (
	"flag"
	"fmt"

	"monitor/rpc/status/internal/config"
	"monitor/rpc/status/internal/server"
	"monitor/rpc/status/internal/svc"
	"monitor/rpc/status/status"

	"github.com/tal-tech/go-zero/core/conf"
	"github.com/tal-tech/go-zero/core/logx"
	"github.com/tal-tech/go-zero/zrpc"
	"google.golang.org/grpc"
)

var configFile = flag.String("f", "etc/status.yaml", "the config file")

func main() {
	flag.Parse()

	cl := logx.LogConf{
		Mode:     "file",
		Path:     "logs",
		KeepDays: 7,
	}
	logx.MustSetup(cl)
	defer logx.Close()

	logx.Info("this is info")
	logx.Error("this is error")
	logx.CollectSysLog()
	//logx.ErrorStack("hello")
	//logx.Errorf("%s and %s", "hello", "world")
	//logx.Severef("%s severe %s", "hello", "world")
	logx.Slowf("%s slow %s", "hello", "world")
	logx.Statf("%s stat %s", "hello", "world")

	var c config.Config
	conf.MustLoad(*configFile, &c)
	ctx := svc.NewServiceContext(c)
	srv := server.NewStatusUploaderServer(ctx)

	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
		status.RegisterStatusUploaderServer(grpcServer, srv)
	})
	defer s.Stop()

	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
	s.Start()
}
